package com.hugo.vod.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.DeleteVideoRequest;
import com.hugo.commonutiles.R;
import com.hugo.serviceconfig.exceptionhandler.HugoException;
import com.hugo.vod.Utils.ConstantVodUtils;
import com.hugo.vod.Utils.InitVideo;
import com.hugo.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {
    @Autowired
    private VodService vodService;

    @PostMapping("uploadAliyunVideo")
    public R uploadAliyunVideo(MultipartFile file){
    String videoId = vodService.uploadVideoAliyun(file);
    return R.ok().data("videoId",videoId);
    }
    //删除视屏
    @DeleteMapping("deletedVideo/{id}")
    public R deletedVideo(@PathVariable String id){
        try
        {
            //初始化对象
            DefaultAcsClient client = InitVideo.initVodClient(ConstantVodUtils.KEYID, ConstantVodUtils.KEYSECRET);
            //创建删除视屏的request对象
            DeleteVideoRequest request = new DeleteVideoRequest();
            //想request设置id
            request.setVideoIds(id);
            client.getAcsResponse(request);

            System.out.println(id);
            return R.ok();
        } catch (Exception e){
        throw  new HugoException(20001,"视屏删除失败");
        }

    }
    @DeleteMapping("deletedMoreVideo")
    //@RequestParm("参数的名称")
    public R deletedMoreVideo(@RequestParam("viedoIdList") List<String> viedoIdList){
        vodService.removeAliyunVideo(viedoIdList);
        return R.ok();

    }
}
